define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'message/index',
                    multi_url: 'message/multi',
                },
                table: 'message',
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: false,
                visible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible:false,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: 'ID',operate: false},
                        {field: 'content',title:'内容',operate:'like',
                            cellStyle : function(value, row, index, field) {
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        // "text-overflow": "ellipsis",
                                        "overflow": "auto",
                                        "max-width": "250px"
                                    }
                                };}
                        },
                        {field: 'createtime', title: '创建时间', formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
                    ]
                ]
            });

            var options = table.bootstrapTable('getOptions');
            var queryParams = options.queryParams;
            // 绑定TAB事件
            $('.panel-heading a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var value = $(this).data("value");
                options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    if (value) {
                        params.filter = JSON.stringify(value);
                        let op = {}
                        for (let i in value) {
                            op[i] = '=';
                        }
                        params.op = JSON.stringify(op);
                    }
                    params = queryParams.call(this, params);
                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});